#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : Moty
# @Time     : 2024/10/18 22:39
# @File     : kc16_32.py
# @Project  : CSPT
def parse_32_Operational_Platform_Confirms_Charging_Initiation(body):
    # 解析0x25 充电过程 BMS 信息
    data = {
        "交易流水号": f"{body[0:32]}({body[0:32]})",
        "桩编号": f"{body[32:46]}({body[32:46]})",
        "枪号": f"{int(body[46:48], 16)}枪({body[46:48]})",
        "逻辑卡号": f"{body[56:64]}({body[48:64]})",
        "账户余额": f"{int(body[64:72], 16)/100}({body[64:72]})",
        "鉴权成功标志": f"{auth_sign(body[72:74])}({body[72:74]})",
        "失败原因": f"{fail_reason(body[74:76])}({body[74:76]})",
    }
    formatted_data = ""
    for key, value in data.items():
        formatted_data += f"{key}: {value}\n"
    return formatted_data


def auth_sign(result):
    return "失败" if result == "00" else "成功" if result == "01" else "未知"


def fail_reason(result):
    return "账户不存在" if result == "01" else "账户冻结" if result == "02" else "账户余额不足" if result == "03" \
        else "该卡存在未结账记录" if result == "04" else "桩停用" if result == "05" else "该账户不能在此桩上充电" if result == "06" \
        else "密码错误" if result == "07" else "电站电容不足" if result == "08" else "系统中 vin 码不存在" if result == "09" \
        else "该桩存在未结账记录" if result == "0A" else "该桩存在未结账记录" if result == "0B" else "未知"


__all__ = ['parse_32_Operational_Platform_Confirms_Charging_Initiation']
